package S2.client;

import ocsf.client.*;

import java.io.*;

import Controllers.MainControler;
import Controllers.MarketingEmpControler;
import GUI.ClientConnection.ClientConnectToServerGui;
import Message.*;

public class S2Client extends AbstractClient {
	/**
	 * @param args
	 * @throws IOException
	 */

	// private S2ClientUI clientUI;
	private ClientConnectToServerGui clientUI;

	public S2Client(S2ClientUI clientui2) throws IOException {
		super(); // Call the superclass constructor
		// this.clientUI = clientUI;
		this.clientUI = new ClientConnectToServerGui();

		clientui2.setVisible(true);
	}

	public S2Client(String host, int port) throws IOException {
		super(host, port); // Call the superclass constructor
		openConnection();
		// clientUI.setNotification("Connection to server succeeded.");
	}

	public S2Client(String host, int port, S2ClientUI clientUI)
			throws IOException {
		super(host, port); // Call the superclass constructor
		// this.clientUI=clientUI;
		clientUI = clientUI;
		clientUI.setVisible(true);
		openConnection();
		// clientUI.setNotification("Connection to server succeeded.");
	}
	
	
	
	protected synchronized void handleMessageFromServer(Object message) {
		Message msg = (Message) message;
		
		switch (msg.getMsg()) {
		case "UserLogIn":
			MainControler.setRoleFram(msg);
			break;
		case "Add Customer":
			MarketingEmpControler.addCustomerReturnMsg(msg);//returend message to MarketingEmpControler.
			break;
		case "Add Product":
			MarketingEmpControler.addProductReturnMsg(msg);
			break;
		case "Add Contact Customer":
			MarketingEmpControler.addContactCusReturnMsg(msg);
			
			break;
		default:
			break;
		}

	}

	public void quit() {
		try {
			closeConnection();
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.exit(0);
	}

}
